package subject1.xutfEncoding;

/**
 * @Author Administrator
 * @Date 2022/12/21--22:46
 * @Description
 */
public class Main {
    private static String xutfEncoding(int unicodeVal) {
        // 先将十进制转成二进制
        if (unicodeVal < 1 << 7) {
            return String.format("%02X", unicodeVal | 1 << 7);
        }
        StringBuffer sb = new StringBuffer();
        int head = 1 << 6;
        while (unicodeVal >= head) {
            sb.insert(0, String.format("%02X", unicodeVal & ((1 << 6) - 1) | 1 << 6));
            unicodeVal >>= 6;
            head >>= 1;
        }
        sb.insert(0, String.format("%02X", unicodeVal | head));
        return sb.toString();
    }
    public static void main(String[] args) {
        System.out.println(Main.xutfEncoding(21326));
        System.out.println(Main.xutfEncoding(34));
        System.out.println(Main.xutfEncoding(1225859));
    }
}
